<?php
// +----------------------------------------------------------------------
// | Demo [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.lmx0536.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: limx <715557344@qq.com> <http://www.lmx0536.cn>
// +----------------------------------------------------------------------
// | Date: 2016/4/27 Time: 11:01
// +----------------------------------------------------------------------

namespace Home\Controller;
use Home\Common\AuthController;

class TraceController extends AuthController
{
    public function index()
    {
        $this -> display();
    }

    public function add($id = "")
    {
        if (fnCheckInts($id)) {
            $M = D("Trace");
            $condition ["Id"] = $id;
            $res = $M -> mfnFind($condition);
            if ($res) {
                $this -> assign("info", $res);
            }
        }

        //拆解分类信息
        $C = D("Cate");
        $condition=" del_status = 0";
        $rs = $C->mfnSelect($condition);
        if($rs["data"]){
            $data = $rs["data"];
            foreach($data as $i => $v){
                $data[$i]["info"] = unserialize($v["info"]);
            }
            $this->assign("cate",$data);
        }
        else{
            $this->error("请先设置分类！","/Home/Cate/index");
        }

        $this -> display();
    }

    /**
     * [pfnDel 删除]
     * @author limx
     * @param $id
     */
    public function pfnDel($id = "")
    {
        if (fnCheckInts($id)) {
            $M = D("Trace");
            $res = $M -> mfnDelete($id);
            if ($res) {
                $this -> lfnAjaxSuccess();
            }
            $this -> lfnAjaxFailed($M -> getError());
        } else {
            $this -> lfnAjaxFailed(C("SYSTEM_REFUSE_MSG"));
        }
    }

    /**
     * [pfnGetList 获取信息列表]
     * @author limx
     */
    public function pfnGetList()
    {
        if (IS_POST) {
            $M = D("Trace");
            $pageIndex = I("post.pageIndex");
            $pageSize = I("post.pageSize");
            $condition = " 1=1 ";
            $res = $M -> mfnSelect($condition, $pageIndex, $pageSize);
            if ($res) {
                $this -> lfnAjaxSuccess($res);
            }
            $this -> lfnAjaxFailed($M -> getError());
        }
        $this -> lfnAjaxFailed(C("SYSTEM_ERROR_MSG"));
    }

    /**
     * [pfnAddCarLog 新增]
     * @author limx
     */
    public function pfnAdd()
    {
        if (IS_POST) {
            $data ["Id"] = I("post.id");
            //读入数据
            $this -> lfnAjaxFailed("模版添加");
            
            $M = D("Trace");
            $res = $M -> mfnUpdate($data);
            if ($res !== false) {
                $this -> lfnAjaxSuccess();
            } else {
                $this -> lfnAjaxFailed($M -> getError());
            }
        }
        $this -> lfnAjaxFailed(C("SYSTEM_ERROR_MSG"));
    }

}